package com.flycent.hqhs.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import com.flycent.hqhs.R;

/**
 * @author fbl
 * 评价/晒单
 */
public class EvaluationActivity extends BackableTitleBarActivity{
	private Fragment[] mFragments;
	private RadioGroup bottomRg;
	private FragmentManager fragmentManager;
	private FragmentTransaction fragmentTransaction;
	@SuppressWarnings("unused")
	private RadioButton rbOne, rbTwo;
	
	public static long skuId;
	public static boolean reviewStatus;
	public static boolean sunSingleStatus;
	public static String skuName;
	public static String skuImage;
	public static float  skuPrice;
	public static long orderId;
	public static String skuAttribute;
	
	@Override
	protected void onCreate(Bundle savedInstance) {
		super.onCreate(savedInstance);

		setContentView(R.layout.activity_evaluation);
		getTitleBar().setTitle(R.string.mine_evaluation_or_single);
		
		skuId = getIntent().getLongExtra("skuId", 0);
		orderId = getIntent().getLongExtra("orderId", 0);
		reviewStatus = getIntent().getBooleanExtra("reviewStatus", false);
		sunSingleStatus = getIntent().getBooleanExtra("sunSingleStatus", false);
		skuName = getIntent().getStringExtra("skuName");
		skuImage = getIntent().getStringExtra("skuImage");
		skuAttribute = getIntent().getStringExtra("skuAttribute");
		skuPrice = getIntent().getFloatExtra("skuPrice", 0);
		
		
		mFragments = new Fragment[2];
		fragmentManager = getSupportFragmentManager();
		mFragments[0] = fragmentManager.findFragmentById(R.id.fragment_evaluation);
		mFragments[1] = fragmentManager.findFragmentById(R.id.fragment_single);
		fragmentTransaction = fragmentManager.beginTransaction()
				.hide(mFragments[0]).hide(mFragments[1]);
		if( !reviewStatus ){
			fragmentTransaction.show(mFragments[0]).commit();
		}else {
			fragmentTransaction.show(mFragments[1]).commit();
		}
		setFragmentIndicator();
	}


	private void setFragmentIndicator() {

		bottomRg = (RadioGroup) findViewById(R.id.evaluation_radioGroup);
		rbOne = (RadioButton) findViewById(R.id.evaluation_radio0);
		rbTwo = (RadioButton) findViewById(R.id.evaluation_radio1);
		if( !reviewStatus ){
			bottomRg.check(R.id.evaluation_radio0);
		}else {
			bottomRg.check(R.id.evaluation_radio1);	
		}
		

		bottomRg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				fragmentTransaction = fragmentManager.beginTransaction()
						.hide(mFragments[0]).hide(mFragments[1]);
				switch (checkedId) {
				case R.id.evaluation_radio0:
					fragmentTransaction.show(mFragments[0]).commit();
					break;

				case R.id.evaluation_radio1:
					fragmentTransaction.show(mFragments[1]).commit();
					break;

				default:
					break;
				}
			}
		});
	}

	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		super.onActivityResult(arg0, arg1, arg2);
		
	}
}


